/*
 * This file is part of the Sx Framework Library.
 * 
 * Copyright (C) 2013 University of Colorado Denver
 * <min.choi@ucdenver.edu> <shane.transue@ucdenver.edu>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy 
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 * copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */
#ifndef SX_DISCRETE_COLLISION_EVENT_AGGREGATE_H
#define SX_DISCRETE_COLLISION_EVENT_AGGREGATE_H

#include <sxCollisionEventPool.h>
#include <sxCollisionEventAggregate.h>

namespace Sx {
namespace Physics {
namespace Collision {
namespace Aggregates {

/* A discrete collision event aggregate combines the types of collision events
 * that can be generated in a discrete graphics environment. A discrete
 * environment is formed by vertices, edges, and faces of varying degree.
 * Therefore there is a limited number of possible collision combinations that
 * can occur between these elements. A discrete collision aggregate provides
 * collision arrays for each of these collision combinations.
 */
template <class ObjectType, typename EdgeEdgeEventType, typename VertexFaceEventType, typename VertexEdgeEventType, typename FaceFaceEventType, typename EdgeFaceEventType, typename VertexVertexEventType>
struct DiscreteCollisionEventAggregate : public CollisionEventAggregate<ObjectType> {
	/* Clears all collision events */
	void clear();

	/* Returns the total number of collision events of all types held within
	 * this collision aggregate.
	 */
	unsigned int size();

	Event::CollisionEventPool<EdgeEdgeEventType> eventpool_EdgeEdge;
	Event::CollisionEventPool<VertexFaceEventType> eventpool_VertexFace;
	Event::CollisionEventPool<VertexEdgeEventType> eventpool_VertexEdge;
	Event::CollisionEventPool<FaceFaceEventType> eventpool_FaceFace;
	Event::CollisionEventPool<EdgeFaceEventType> eventpool_EdgeFace;
	Event::CollisionEventPool<VertexVertexEventType> eventpool_VertexVertex;
};

template <class ObjectType, typename EdgeEdgeEventType, typename VertexFaceEventType, typename VertexEdgeEventType, typename FaceFaceEventType, typename EdgeFaceEventType, typename VertexVertexEventType>
void DiscreteCollisionEventAggregate<ObjectType, EdgeEdgeEventType, VertexFaceEventType, VertexEdgeEventType, FaceFaceEventType, EdgeFaceEventType, VertexVertexEventType>::clear() {
	for ( unsigned int i = 0; i < this->eventpool_VertexFace.capacity(); i++ ) {
		this->eventpool_VertexFace[i] = VertexFaceEventType();
	}
	
	this->eventpool_EdgeEdge.clear();
	this->eventpool_EdgeFace.clear();
	this->eventpool_FaceFace.clear();
	this->eventpool_VertexFace.clear();
	this->eventpool_VertexEdge.clear();
	this->eventpool_VertexVertex.clear();
}

template <class ObjectType, typename EdgeEdgeEventType, typename VertexFaceEventType, typename VertexEdgeEventType, typename FaceFaceEventType, typename EdgeFaceEventType, typename VertexVertexEventType>
unsigned int DiscreteCollisionEventAggregate<ObjectType, EdgeEdgeEventType, VertexFaceEventType, VertexEdgeEventType, FaceFaceEventType, EdgeFaceEventType, VertexVertexEventType>::size() {
	return this->eventpool_EdgeEdge.size() + this->eventpool_EdgeFace.size() + this->eventpool_FaceFace.size() + this->eventpool_VertexFace.size() + this->eventpool_VertexVertex.size();
}

}

}

}

}

#endif
